﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using DbAdapter.sqldbAdapter;
using System.Data.SqlClient;

namespace DAO.WaiGaoQiao
{


    public class DataAccessWork_Gas
    {
        /// <summary>
        /// 根据id获取天然气录入对象
        /// </summary>
        /// <returns></returns>
        public DataSet GetWork_GasById(int Id)
        {
            sqldb db = new sqldb();
            string query = "select [ID],[CBDT],[GroupNo],[GroupMan] ,[MachNo],[OpenMachDt],[StopMachDt],[RanqiType],[TeamNo],[StartTime],[OneTime],[TwoTime],  " + " [ThreeTime] ,[FourTime],[FiveTime] ,[SixTime] ,[SevenTime] ,[EightTime] ,[NineTime] ,[TenTime],[ElevenTime],[CreateDt] " +
                             " from Work_Gas where 1=1 and Id = " + Id;
            return db.ExecuteDataset(GetConntionString.conntionstring(), CommandType.Text, query);
        }


        /// <summary>
        /// 根据条件获取所有天然气录入。
        /// </summary>
        /// <returns></returns>
        public DataSet GetAllWork_Gas(string condition)
        {
            sqldb db = new sqldb();
            string query = "select [ID],[CBDT],[GroupNo],[GroupMan] ,[MachNo],[OpenMachDt],[StopMachDt],[RanqiType],[TeamNo],[StartTime],[OneTime],[TwoTime],  " + " [ThreeTime] ,[FourTime],[FiveTime] ,[SixTime] ,[SevenTime] ,[EightTime] ,[NineTime] ,[TenTime],[ElevenTime],[CreateDt] " +
                             " from Work_Gas where 1=1 " + condition;
            return db.ExecuteDataset(GetConntionString.conntionstring(), CommandType.Text, query);
        }

        /// <summary>
        /// 获取所有天然气录入(分页）
        /// </summary>
        /// <returns></returns>
        public DataSet GetAllWork_Gas(string Condition, int pagesize, int startindex)
        {
            using (SqlConnection conn = new SqlConnection(GetConntionString.conntionstring()))
            {
                sqldb db = new sqldb();
                int startrow = pagesize * (startindex - 1);
                int endrow = pagesize * startindex + 1;
                string query = "select B.[ID],B.[CBDT],B.[GroupNo],B.[GroupMan] ,B.[MachNo],B.[OpenMachDt],B.[StopMachDt]," +
                               " B.[RanqiType],B.[TeamNo],B.[StartTime],B.[OneTime],B.[TwoTime],B.[ThreeTime] ,B.[FourTime],B.[FiveTime] ," +
                               " B.[SixTime] ,B.[SevenTime] ,B.[EightTime] ,B.[NineTime] ,B.[TenTime],B.[ElevenTime],B.[CreateDt] " +
                               " from (select ROW_NUMBER() OVER(ORDER BY A.ID DESC) rownumber," +
                               " A.[ID],A.[CBDT],A.[GroupNo],A.[GroupMan] ,A.[MachNo],A.[OpenMachDt],A.[StopMachDt]," +
                               " A.[RanqiType],A.[TeamNo],A.[StartTime],A.[OneTime],A.[TwoTime],A.[ThreeTime] ,A.[FourTime],A.[FiveTime] ," +
                               " A.[SixTime] ,A.[SevenTime] ,A.[EightTime] ,A.[NineTime] ,A.[TenTime],A.[ElevenTime],A.[CreateDt] " +
                               " from Work_Gas A where 1=1 " + Condition + ") B " +
                             "where B.rownumber > " + startrow.ToString() + " and B.rownumber < " + endrow.ToString();
                return db.ExecuteDataset(conn, CommandType.Text, query);
            }
        }

        /// <summary>
        /// 保存或修改天然气录入
        /// </summary>
        /// <param name="dmpara"></param>
        /// <returns></returns>
        public int SaveWork_Gas(object[] GasType)
        {
            sqldb db = new sqldb();
            string insert = "INSERT INTO [WaiGaoqiao].[dbo].[Work_Gas]([CBDT],[GroupNo],[GroupMan],[MachNo],[OpenMachDt],[StopMachDt],[RanqiType],[TeamNo],[StartTime],[OneTime], " +
                            " [TwoTime] ,[ThreeTime] ,[FourTime] ,[FiveTime],[SixTime],[SevenTime],[EightTime],[NineTime],[TenTime] ,[ElevenTime],[CreateDt]) VALUES " +
                            " (" + GasType[0] + "," + GasType[1] + "," + GasType[2] + "," + GasType[3] + "," + GasType[4] + "," + GasType[5] + "," + GasType[6] + "," + GasType[7] + "," + GasType[8] + "," + GasType[9] + "," + GasType[10] + "," +
                            " " + GasType[11] + "," + GasType[12] + "," + GasType[13] + "," + GasType[14] + "," + GasType[15] + "," + GasType[16] + "," + GasType[17] + "," + GasType[18] + "," + GasType[19] + "," + GasType[20] + ")";
            return db.ExecuteNonQuery(GetConntionString.conntionstring(), CommandType.Text, insert);

        }


        /// <summary>
        /// 删除天然气录入
        /// </summary>
        /// <param name="did"></param>
        /// <returns></returns>
        public int DeleteWork_Gas(string id)
        {
            sqldb db = new sqldb();
            string query = "delete from Work_Gas where  id = " + id;
            return db.ExecuteNonQuery(GetConntionString.conntionstring(), CommandType.Text, query);
        }

        /// <summary>
        /// 根据条件获取所有天然气录入数量
        /// </summary>
        /// <returns></returns>
        public int GetWork_GasCount(string Condition)
        {
            sqldb db = new sqldb();
            string query = "select count(1) from Work_Gas where 1=1 " + Condition;
            object rowcount = db.ExecuteScalar(GetConntionString.conntionstring(), CommandType.Text, query);
            return Convert.ToInt32(rowcount);
        }



    }
}
